package Question4;

import java.util.Scanner;
import java.util.Vector;

/**
 * Created by lenovo on 2017/3/7.
 */
public class Main {
    public  static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        Vector<Character> characters = new Vector<>();
        for(int i=0;i<26;i++){
            characters.add((char)('A'+i));
        }
        int n = Integer.parseInt(scanner.nextLine());
        while (n-->0){
            String str = scanner.nextLine();
            Integer rowNumber = str.indexOf("R");
            Integer colNumber = str.indexOf("C");

            rowNumber = Integer.parseInt(str.substring(rowNumber+1,colNumber));
            colNumber = Integer.parseInt(str.substring(colNumber+1,str.length()));

            int shang = colNumber/26-1;
            int yuShu = colNumber%26-1;

            String output = "";
            if(shang>0){
                output+=characters.elementAt(shang);
            }

            //这里组合出现一些问题，int要先转换成字符串模式
            output+=characters.elementAt(yuShu)+rowNumber.toString();
            System.out.println(output);
        }
    }
}
